﻿------------------------------------------------------------
-- Table : Debts
------------------------------------------------------------
-- Author : Sam Beauvois
-- Creation Date : 2009-11-18
-- Modification User : Sam Beauvois
-- Modification Date : 2009-11-18
------------------------------------------------------------
 

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'Debts')
BEGIN	
	CREATE TABLE [Debts]
	(
		[ID] [bigint]  NOT NULL PRIMARY KEY IDENTITY(1,1),
		[Lender] [bigint] NULL,
		[Indebted] [bigint] NULL,
		[Amount] [float] NOT NULL,
		[LoadDate] [datetime] NULL,
		[Comment] [nvarchar](max) NULL,
		[Paid] [bit] NULL,
		[PaidDate] [datetime] NULL,
		[Private] [bit] NULL
	)
END
GO

IF NOT EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'FK_Debts_People') AND type = (N'F'))
BEGIN
	ALTER TABLE [Debts]  ADD  CONSTRAINT [FK_Debts_People] FOREIGN KEY([Lender]) REFERENCES [People] ([ID])
END
GO

IF NOT EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'FK_Debts_People1') AND type = (N'F'))
BEGIN
	ALTER TABLE [Debts]  ADD  CONSTRAINT [FK_Debts_People1] FOREIGN KEY([Indebted]) REFERENCES [People] ([ID])
END
GO
